dojo.provide("medryx.rpc.tests.MockPersistenceServiceTest");
dojo.require("medryx.rpc.mock.MockPersistenceService");
dojo.require("doh.runner");
dojo.require("doh.TestCase");

(function() {
    dojo.declare("medryx.MockClass", null, {
		id:null,
		value:null
	});
	
	var scaffold = {
		setUp:function() {
			this.service = new medryx.rpc.mock.MockPersistenceService({
				"medryx.MockClass":dojo.moduleUrl("medryx.rpc", "tests/support/mockItems.js")
			});
		}
	}
	doh.register("medryx.rpc.tests.MockPersistenceServiceTest", [

new doh.AsyncTestCase("test load", function() {
	return service.load("medryx.MockClass", 3, ["*"]);
}, function(result) {
	assertEqual("item 3", result.value);
}, scaffold),


new doh.AsyncTestCase("test fetch", function() {
    return service.fetch("medryx.MockClass", {query:{value:"item 2"}});
}, function(result) {
    assertEqual("item 2", result[0].value);
}, scaffold),

new doh.AsyncTestCase("test save", function() {
    return service.save("medryx.MockClass", null, {value:"new value"});
}, function(result) {
	assertTrue(1006, result);
	assertEqual("new value", service.cache["medryx.MockClass"][1006].value);
}, scaffold),

new doh.AsyncTestCase("test delete", function() {
	service.load("medryx.MockClass", 3, ["*"]);
	assertNotNull(service.cache["medryx.MockClass"][1]);
    return service.deleteItem("medryx.MockClass", 1);
}, function(result) {
    assertNull(service.cache["medryx.MockClass"][1]);
}, scaffold)
	
	
	]);
	
})();



